<template>
<h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="user.username">
  <input type="text" placeholder="请输入员工工资" v-model="user.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="user.job">
  <button @click="reg">点我添加</button>
  <hr>
  <table border="1px">
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(item,index) in userArr">
      <td>{{index+1}}</td>
      <td>{{item.username}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const user=ref(
  {username:'', salary:'', job:''}
);
const userArr=ref([]);
const  reg=()=>{
  if (user.value.username.trim()=='' || user.value.salary.trim()==''||user.value.job.trim()==''){
    alert('请输入完整信息');
    return;
  }
  //将手机到的员工数据存入数组，并清空对应的输入框
  userArr.value.push(user.value);
  user.value={username:'', salary:'', job:''};
}

</script>

<style scoped>

</style>